<template>
	<view class="page page-fill">
		<view class="face line-bar" @click="operator">
			<view class="name-type">
				头像
			</view>
			<view class="name-wrap">
				<image class="face-img" :src="userInfo.faceImage" mode=""></image>
				<image src="../../static/icon/arror-icon.png" class="arror-icon" mode=""></image>
			</view>
		</view>

		<view class="line-bar" @click="menickName">
			<view class="name-type">
				昵称
			</view>
			<view class="name-wrap">
				<view class="name-text">
					{{userInfo.nickname}}
				</view>
				<image class="arror-icon" src="../../static/icon/arror-icon.png" mode=""></image>
			</view>
		</view>

		<view class="line-bar" @click ="toBirthday">
			<view class="name-type">
				生日
			</view>
			<view class="name-wrap">
				<view class="name-text">
					{{userInfo.birthday}}
				</view>
				<image class="arror-icon" src="../../static/icon/arror-icon.png" mode=""></image>
			</view>
		</view>

		<view class="line-bar" @click = "toChangeSex">
			<view class="name-type">
				性别
			</view>
			<view class="name-wrap">
				<view class="name-text" v-if="userInfo.sex === 1">
					男
				</view>
				<view class="name-text" v-else-if="userInfo.sex === 0">
					女
				</view>
				<view class="name-text" v-else="userInfo.sex === ">
					未选择
				</view>
				<image class="arror-icon" src="../../static/icon/arror-icon.png" mode=""></image>
			</view>
		</view>

		<view class="btn-bottom">
			<view class="clear-cache btn" @click="clearCache">清理缓存</view>
			<view class="login-out  btn" @click="logoOut">退出登录</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: ''
			}
		},
		
		onShow() {
			var userInfo = uni.getStorageSync('globalInfo');
			this.userInfo = userInfo;
		},
		methods: {
			toChangeSex(){
		      var userInfo = uni.getStorageSync("globalInfo")
			  uni.navigateTo({
			  	url:'../changeSex/changeSex'
			  });
			},
			menickName(){
				var userInfo = uni.getStorageSync("globalInfo")
				uni.navigateTo({
					url:'../meNickname/meNickname?nickname='+userInfo.nickname
				});
			},
			toBirthday(){
			     var userInfo = uni.getStorageSync("globalInfo");
				 uni.navigateTo({
				 	url:'../birthday/birthday?birthday='+userInfo.birthday
				 });
			},
			operator() {
				var userInfo = uni.getStorageSync('globalInfo');

				uni.showActionSheet({
					itemList: ["查看我的头像", "从相册上传头像"],
					success(res) {
						var index = res.tapIndex;
						console.log(res);
						if (index == 0) {
							console.log(userInfo.faceImage);
							var faceArr = [];
							faceArr.push(userInfo.faceImage);


							uni.previewImage({
								urls: faceArr,
								current: faceArr[0]
							})
						} else if (index === 1) {
							uni.chooseImage({
								count: 0,
								sizeType: ['compressed'],
								sourceType: ['album'],
								success: (res) => {
									console.log(res);
									var tempFilePath = res.tempFilePaths[0];
									// #ifdef H5
									uni.navigateTo({
										url: '../meFace/meFace?tempFilePath=' + tempFilePath
									})
									// #endif
									// #ifndef H5
									uni.navigateTo({
										url: "../faceCrop/faceCrop?tempFilePath=" + tempFilePath
									})
									// #endif

								}
							})

						}
					}
				})
			},
			clearCache() {
				uni.clearStorageSync();
				uni.showToast({
					title: "清除缓存成功",
					mask: true,
					duration: 1000
				})
			},
			logoOut() {
				var userInfo = uni.getStorageSync('globalInfo');
				uni.request({
					method: "POST",
					url: this.serverUrl + '/user/logout?qq=3316368400&userId=' + userInfo.id,
					success: (res) => {
						if (res.data.status === 200) {
							uni.removeStorageSync("globalInfo");
							uni.switchTab({
								url: '../index/index'
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
	@import url("meInfo.css");
</style>
